#include<iostream>
#include<vector>
#define MOD 1000000007
using namespace std;

int main(){
	freopen("input.txt","r",stdin);
	string s;
	cin>>s;
	int len=s.length(),result=0,countp=0,countt=0;
	for(int i=0;i<len;i++){
		if(s[i]=='T') countt++;
	}
	for(int i=0;i<len;i++){
		if(s[i]=='P') countp++;
		if(s[i]=='T') countt--;
		if(s[i]=='A') result=(result+countp*countt)%MOD;
	}
	cout<<result;
	return 0;
}